<template>
  <div>
    <div class="main">
      <h1>登录注册表单切换</h1>
      <div class="w3_login">
        <div class="w3_login_module">
          <div class="module form-module">
            <div class="toggle">
              <i class="fa fa-times fa-pencil" @click="funcson"></i>
              <div class="tooltip" tag="span">点击切换</div>
            </div>
            <div class="form">
              <h2>登录账号</h2>
              <form action="#" method="post" @submit.prevent="submit($event)">
                <input type="text" name="name" v-model="username" placeholder="用户名" required=""/>
                <input type="password" name="password" v-model="password" placeholder="密码" required=" "/>
                <input type="submit" value="登录"/>
              </form>
            </div>
            <div class="cta"><a href="#">忘记密码?</a></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      login_visible: false,
      username: '',
      password: ''
    }
  },
  methods: {
    funcson (v) {
      this.$emit('func', this.login_visible)
    },
    submit: function (event) {
      var formData = new FormData(event.target)
      this.$http.post('http://localhost:8001/login',
        formData).then(function (d) {
        if (d.body) {
          console.log(d.body)
          // eslint-disable-next-line no-undef
          // this.mui.toast('登陆成功')// 调用mui的组件
          this.$router.push('/contain')
        } else {
          // this.mui.toast('登陆失败')// 调用mui的组件
          //  this.$router.push('/')
        }
      }, function () {

      }
      )
    }
  }
}
</script>

<style scoped>
  login {
    background: url(../images/banner.jpg) no-repeat 0px 0px;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    -ms-background-size: cover;
    background-attachment: fixed;
  }
</style>
